/*
 * Copyright 2011 myTDev.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.mytdev.swing.actions;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
 * The Action annotation.
 * Placed on a method it defines an action. The method is the action execution 
 * code. The annotation value is used as a key for the action, if not specified 
 * then the method name is used.
 * The thread property defines if the action is executed in a new thread 
 * (background) or in the Event Dispatch Thread. 
 * The method must be a zero argument method or have only one argument assignable 
 * from ActionEvent class.
 * 
 * Placed on a field it defines a link .
 * The annotation value is mandatory and must match a defined action.
 * The thread element is ignored.
 * The field must be (or be a subclass of) an AbstractButton, a JTextField or a JComboBox.
 * 
 * @author Yann D'Isanto
 */
@Target({ElementType.METHOD, ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
public @interface Action {

    /** The action key. Default is empty string and so the method name is used. */
    String value() default "";

    /** 
     * If the action must be executed in background or in the EDT. 
     * Default is background. 
     */
    Thread thread() default Thread.BACKGROUND;

    public enum Thread {

        BACKGROUND,
        EDT;
    }
}
